import { createApp } from "vue";
import {
  qiankunWindow,
  QiankunProps,
  renderWithQiankun,
} from "vite-plugin-qiankun/dist/helper";
import "./style.css";
import App from "./App.vue";

function render(props = {}) {
  const { container } = props;
  const app = createApp(App);
  if (container) {
    app.mount(container.querySelector("#app"));
  } else {
    app.mount("#app");
  }
}

// 检查是否在 Qiankun 环境中
console.log("qiankunWindow", qiankunWindow.__POWERED_BY_QIANKUN__);

if (qiankunWindow.__POWERED_BY_QIANKUN__) {
  // 以子应用的方式启动
  renderWithQiankun({
    mount(props) {
      render(props);
    },
    bootstrap() {
      console.log("[vue3-vite] vue3-vite bootstraped");
    },
    unmount() {
      app.unmount();
    },
    update(props) {
      console.log("update", props);
    },
  });
} else render();
